-
Notifications
You must be signed in to change notification settings - Fork 234
Add the Position class for GMT embellishment placement #4212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| #: Specify the reference point on the plot. The method of defining the reference | ||
| #: point is controlled by ``type``, and the exact location is set by ``position``. | ||
| location: Sequence[float | str] | AnchorCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
position or location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think location is better as the parameter is already called position and we overall will have the Position class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring above calls this 'reference point', so how about something like ref or refpt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe refpoint?
In fact, I'd prefer to make it a positional-only parameter, so it will be used like Position("TL", type="inside"), Position((1, 2)).
In this case, the specific parameter name doesn't really matter, though dataclasses doesn't support positional-only attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I did think of positional-only, but a little tricky with dataclasses as you said. Ok to got with refpoint, but let's see what @yvonnefroehlich thinks.
| @dataclasses.dataclass(repr=False) | ||
| class Position(BaseParam): | ||
| """ | ||
| Class for positioning embellishments on a plot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstrings are modified from the GMT documentation at https://docs.generic-mapping-tools.org/dev/reference/features.html#reference-and-anchor-point-specification.
| ``type="boxcoords"`` Normalized Coordinates | ||
| Use normalized coordinates where (0, 0) is the lower-left corner and (1, 1) is | ||
| the upper-right corner of the bounding box of the current plot. Specify | ||
| ``location`` as (*nx*, *ny*). Useful for positioning relative to plot dimensions | ||
| without units. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #: If not specified, defaults to ``"inside"`` if ``location`` is a justification | ||
| #: code; otherwise defaults to ``"plotcoords"``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In GMT, the default is "plotcoords", i.e., the code x. Thus, -D1/1 is equivalent to -Dx1/1.
When location is an anchor code, we know that "plotcoords" makes no sense (e.g., -DxTL). type should be either "inside" or "outside". Here, I choose "inside" as the default.
| _valid_anchors = {f"{h}{v}" for v in "TMB" for h in "LCR"} | { | ||
| f"{v}{h}" for v in "TMB" for h in "LCR" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably can reuse these codes to validate anchor codes in other wrappers, e.g., the justify parameter in the text module. But I feel we can do it in the future.

See #4168 (comment) for context.
This PR implements the
Positionclass.Usage:
GMT Documentation: https://docs.generic-mapping-tools.org/dev/reference/features.html#reference-and-anchor-point-specification
Preview: https://pygmt-dev--4212.org.readthedocs.build/en/4212/api/generated/pygmt.params.Position.html